package com.superteam.zzl.model.Search;

import android.util.Log;

import com.superteam.zzl.app.MyApplication;
import com.superteam.zzl.cans.ContentURLs;
import com.superteam.zzl.retrofit.Search.SearchRetrofit;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by zhang on 2017/1/14.
 */

public class LoadMoreData {

    private SearchMoreData data;

    public LoadMoreData(SearchMoreData data, String url,int type) {
        this.data = data;
        loadData(url,type);
    }

    private void loadData(String url,int type) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://www.qiugonglue.com/").
                addConverterFactory(ScalarsConverterFactory.create()).
                addConverterFactory(GsonConverterFactory.create()).
                build();
        SearchRetrofit sr = retrofit.create(SearchRetrofit.class);
        switch (type) {
            case 1://更多动态
                Call<DynData> callDyn = sr.getDynData(url);
                callDyn.enqueue(new Callback<DynData>() {
                    @Override
                    public void onResponse(Call<DynData> call, Response<DynData> response) {
                        data.sendDyn((ArrayList<DynData.TrendListBean>) response.body().getTrendList());
                    }
                    @Override
                    public void onFailure(Call<DynData> call, Throwable t) {

                    }
                });
                break;
            case 2://更多商品
                Call<ShopData> callShop = sr.getShopData(url);
                callShop.enqueue(new Callback<ShopData>() {
                    @Override
                    public void onResponse(Call<ShopData> call, Response<ShopData> response) {
                        data.sendShop((ArrayList<ShopData.ProductListBean>) response.body().getProductList());
                    }

                    @Override
                    public void onFailure(Call<ShopData> call, Throwable t) {

                    }
                });
                break;
            case 3://更多旅行地
                Call<PoiData> callPoi = sr.getPoiData(url);
                callPoi.enqueue(new Callback<PoiData>() {
                    @Override
                    public void onResponse(Call<PoiData> call, Response<PoiData> response) {
                        data.sendPoi((ArrayList<PoiData.PoiListBean>) response.body().getPoiList());
                    }

                    @Override
                    public void onFailure(Call<PoiData> call, Throwable t) {

                    }
                });
                break;
            case 4://更多用户
                Call<UserData> callUser = sr.getUserData(url);
                callUser.enqueue(new Callback<UserData>() {
                    @Override
                    public void onResponse(Call<UserData> call, Response<UserData> response) {
                        data.sendUser((ArrayList<UserData.UserListBean>) response.body().getUserList());
                    }

                    @Override
                    public void onFailure(Call<UserData> call, Throwable t) {

                    }
                });
                break;
            case 5://更多群组
                break;

        }

    }
}
